//
//  SuperviseAPI.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/1/7.
//

import Foundation
import HandyJSON

// MARK: - 检查监督

// MARK: - URL
let URLJcjdStatics = "/jcjd/statics" /// 根据部门查询完成率
let URLJcjdHome = "/jcjd/home" /// 待整改、待复查 统计数字
let URLJcjdRwlb = "/jcjd/rwlb" /// 新建选择-任务列表
let URLJcjdCjrw = "/jcjd/cjrw" /// 创建检查任务
let URLJcjdRwzs = "/jcjd/rwzs" /// 任务数量
let URLJcjdRwbg = "/jcjd/rwbg" /// 任务列表-待完成/已完成
let URLJcjdKsjcrw = "/jcjd/ksjcrw" /// 开始检查-任务详情
let URLJcjdKsjctj = "/jcjd/ksjctj" /// 开始检查-检查结果提交
let URLJcjdRwbgxq = "/jcjd/rwbgxq" /// 任务报告详情
let URLJcjdRwpllb = "/jcjd/rwpllb" /// 任务评论列表
let URLJcjdRwpltj = "/jcjd/rwpltj" /// 发表评论
let URLJcjdRwbgjc = "/jcjd/rwbgjc" /// 任务报告-检查情况
let URLJcjdRwbgtz = "/jcjd/rwbgtz" /// 任务报告-调整情况
let URLJcjdRwbgtzxq = "/jcjd/rwbgtzxq" /// 任务报告-调整情况
let URLJcjdRwzg = "/jcjd/rwzg" /// 待整改
let URLJcjdRwzgxq = "/jcjd/rwzgxq" /// 待整改详情
let URLJcjdRwzgtj = "/jcjd/rwzgtj" /// 整改提交
let URLJcjdRwzgfc = "/jcjd/rwzgfc" /// 待复查
let URLJcjdRwzgfcxq = "/jcjd/rwzgfcxq" /// 待复查详情
let URLJcjdRwzgfctj = "/jcjd/rwzgfctj" /// 复查提交

// MARK: - API
/// Common
struct SpCommonParam: Encodable {
    var status: Int?
    var wddm: Int64?
    var rwkssj: String?
    var rwjssj: String?
    var rwlxmc: String?
    var pageSize: Int?
    var pageNum: Int?
    
    var timestamp: String?
    var signature: String?
    
    init(status: Int? = nil, wddm: Int64? = nil, rwkssj: String? = nil, rwjssj: String? = nil, rwlxmc: String? = nil, pageSize: Int? = nil, pageNum: Int? = nil) {
        self.status = status
        self.wddm = wddm
        self.rwkssj = rwkssj
        self.rwjssj = rwjssj
        self.rwlxmc = rwlxmc
        self.pageSize = pageSize
        self.pageNum = pageNum
    }
}

struct SpStaticsParam: Encodable {
    var deptId: Int64?
    var dateType: Int?
    var date: String?
    
    var timestamp: String?
    var signature: String?
    
    init(deptId: Int64? = nil, dateType: Int? = nil, date: String? = nil) {
        self.deptId = deptId
        self.dateType = dateType
        self.date = date
    }
}

struct SuperviseParam: Encodable {
    var rwlxdms: String?
    var wddms: String?
    
    var timestamp: String?
    var signature: String?
    
    init(rwlxdms: String? = nil, wddms: String? = nil) {
        self.rwlxdms = rwlxdms
        self.wddms = wddms
    }
}

struct SpDetailParam: Encodable {
    var id: Int64?
    var rwjlid: Int64?
    var plnr: String?
    
    var timestamp: String?
    var signature: String?

    init(id: Int64? = nil, rwjlid: Int64? = nil, plnr: String? = nil) {
        self.id = id
        self.rwjlid = rwjlid
        self.plnr = plnr
    }
}

struct ZgjlParam: Encodable {
    var id: String? //复查详情-整改记录ID
    var rwxid: Int64? //任务项ID
    var rwjlid: Int64? //任务ID
    var rwzt: String?
    
    var timestamp: String?
    var signature: String?
    
    init(id: String? = nil, rwxid: Int64? = nil, rwjlid: Int64? = nil, rwzt: String? = nil) {
        self.id = id
        self.rwxid = rwxid
        self.rwjlid = rwjlid
        self.rwzt = rwzt
    }
}

struct RwzgfctjParam: Encodable {
    var id: Int64 // 任务ID
    var zgjls: [ZgjlParam]
    
    var timestamp: String?
    var signature: String?
    
    init(id: Int64, zgjls: [ZgjlParam]) {
        self.id = id
        self.zgjls = zgjls
    }
}


extension API {
    /// 根据部门查询完成率
    class func getJcjdStatics(withParam _param: SpStaticsParam, block: ResponseBlock<CommonScaleByDeptModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdStatics, method: .get, parameters: param, modelType: CommonScaleByDeptModal.self, resultBlock: block)
    }
    
    /// 待整改、待复查 统计数字
    class func getJcjdHome(withParam _param: SpCommonParam, block: ResponseBlock<SpHomeModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdHome, method: .get, parameters: param, modelType: SpHomeModal.self, resultBlock: block)
    }
    
    /// 新建选择-任务列表
    class func getJcjdRwlb(withParam _param: SpCommonParam, block: ResponseBlock<SpRwlbModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwlb, method: .get, parameters: param, modelType: SpRwlbModal.self, resultBlock: block)
    }
    
    /// 创建检查任务
    class func postJcjdCjrw(withParam _param: CommonJsonParam, block: ResponseBlock<ResponseData>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdCjrw, parameters: param, modelType: ResponseData.self, resultBlock: block)
    }
    
    /// 任务数量
    class func getJcjdRwzs(withParam _param: SpCommonParam, block: ResponseBlock<SpHomeModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwzs, method: .get, parameters: param, modelType: SpHomeModal.self, resultBlock: block)
    }
    
    /// 任务列表-待完成/ 已完成
    class func getJcjdRwbg(withParam _param: SpCommonParam, block: ResponseBlock<SpRwbgModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwbg, method: .get, parameters: param, modelType: SpRwbgModal.self, resultBlock: block)
    }
    
    /// 开始检查-任务详情
    class func getJcjdKsjcrw(withParam _param: SpDetailParam, block: ResponseBlock<SpRwbgModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdKsjcrw, method: .get, parameters: param, modelType: SpRwbgModal.self, resultBlock: block)
    }
    
    /// 开始检查-检查结果提交
    class func postJcjdKsjctj(withParam _param: CommonJsonParam, block: ResponseBlock<ResponseData>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdKsjctj, parameters: param, modelType: ResponseData.self, resultBlock: block)
    }
    
    /// 任务报告详情
    class func getJcjdRwbgxq(withParam _param: SpDetailParam, block: ResponseBlock<SpRwbgxqModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwbgxq, method: .get, parameters: param, modelType: SpRwbgxqModal.self, resultBlock: block)
    }

    /// 任务评论列表
    class func getJcjdRwpllb(withParam _param: SpDetailParam, block: ResponseBlock<YjwxCommonModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwpllb, method: .get, parameters: param, modelType: YjwxCommonModal.self, resultBlock: block)
    }

    /// 发表评论
    class func getJcjdRwpltj(withParam _param: SpDetailParam, block: ResponseBlock<ResponseData>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwpltj, method: .get, parameters: param, modelType: ResponseData.self, resultBlock: block)
    }
    
    /// 任务报告-检查情况
    class func getJcjdRwbgjc(withParam _param: SpDetailParam, block: ResponseBlock<SpRwbgjcModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwbgjc, method: .get, parameters: param, modelType: SpRwbgjcModal.self, resultBlock: block)
    }
    
    /// 任务报告-调整情况
    class func getJcjdRwbgtz(withParam _param: SpDetailParam, block: ResponseBlock<SpRwbgtzModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwbgtz, method: .get, parameters: param, modelType: SpRwbgtzModal.self, resultBlock: block)
    }
    
    /// 任务报告-调整情况-调整记录
    class func getJcjdRwbgtzxq(withParam _param: SpDetailParam, block: ResponseBlock<SpRwbgtzModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwbgtzxq, method: .get, parameters: param, modelType: SpRwbgtzModal.self, resultBlock: block)
    }
    
    // 待整改
    class func getJcjdRwzg(withParam _param: SpCommonParam, block: ResponseBlock<SpRwbgModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwzg, method: .get, parameters: param, modelType: SpRwbgModal.self, resultBlock: block)
    }
    
    // 待整改详情
    class func getJcjdRwzgxq(withParam _param: SpDetailParam, block: ResponseBlock<SpRwbgtzModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwzgxq, method: .get, parameters: param, modelType: SpRwbgtzModal.self, resultBlock: block)
    }
    
    // 整改提交
    class func postJcjdRwzgtj(withParam _param: CommonJsonParam, block: ResponseBlock<ResponseData>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwzgtj, parameters: param, modelType: ResponseData.self, resultBlock: block)
    }
    
    // 待复查
    class func getJcjdRwzgfc(withParam _param: SpCommonParam, block: ResponseBlock<SpRwbgModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwzgfc, method: .get, parameters: param, modelType: SpRwbgModal.self, resultBlock: block)
    }
    
    // 待复查详情
    class func getJcjdRwzgfcxq(withParam _param: SpDetailParam, block: ResponseBlock<SpRwbgtzModal>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwzgfcxq, method: .get, parameters: param, modelType: SpRwbgtzModal.self, resultBlock: block)
    }
    
    // 复查提交
    class func postJcjdRwzgfctj(withParam _param: CommonJsonParam, block: ResponseBlock<ResponseData>?) {
        let signP = getSign(param: _param)
        var param = _param
        param.timestamp = signP.timestamp
        param.signature = signP.signature
        NetManager.request(url: URLJcjdRwzgfctj, parameters: param, modelType: ResponseData.self, resultBlock: block)
    }
}


// MARK: - Modals

/// 任务数量
struct SpHomeModal: HandyJSON {
    var dfcs: Int64?
    var dzgs: Int64?
    var wcs: Int64?
    var wwcs: Int64?
}

/// 新建选择-任务列表
struct SpRwlbModal: HandyJSON {
    var id: Int64?
    var remark: String?
    var rwlxmc: String?
    var status: String?
}

/// 任务列表
struct SpRwbgModal: HandyJSON {
    var id: Int64? //主键ID
    var wddm: Int64? //网点代码
    var wdmc: String? // "南京分行营业部",
    var ancestors: String? // "南京分行-南京分行-南京分行营业部",
    var rwlxdm: Int64?
    var rwlxmc: String? //任务名称
    var fzrmc: String?
    var rwkssj: String? //任务开始日期
    var rwzt: String? //任务状态： 1 待检查 2 待整改 3 待复查  4 完成  5 作废
    var rwztmc: String? //任务状态描述
    var rwjlMbs: [SpRwjlMbsModal]? /// 任务记录模板列表
}

/// 任务记录模板列表
struct SpRwjlMbsModal: HandyJSON {
    var id: Int64? //任务项ID
    var rwmbid: Int64? // 任务模板ID
    var rwmc: String? // 任务项名称
    var rwlxdm: Int64?
    var rwlxmc: String? // 任务名称
    var rwzt: String? // 任务项状态：1 待检查 2 合格 3不合格 4 不涉及
    var rwztmc: String? // 任务状态描述
}

// 任务报告详情
struct SpRwbgxqModal: HandyJSON {
    var id: Int64? //任务ID
    var wddm: Int64?//网点代码
    var wdmc: String? //网点名称
    var rwlxdm: Int64? //任务类型ID
    var rwlxmc: String? //任务类型名称
    var fzrmc: String? //负责人名称
    var zgfzrmc: String? //"网点管理员"
    var rwkssj: String?
    var rwjssj: String?
    var rwzt: String? //任务状态：1 待检查 2 待整改 3 待复查  4 完成  5 作废
    var rwztmc: String? //"待复查"
    var tjsj: String? //提交时间
    var lng: String?
    var lat: String?
    var location: String?
    var bjrqz: String? //被检人签名
    var rwjlMbs: [SpRwjlMbsModal]? //问题详情
    var xjrqms: [SpFjModal]?
    var wtzs: Int64? //问题总数
    var jczs: Int64? //检查总数
    var hgzs: Int64? //合格总数
    var bsjzs: Int64? //不涉及总数
    var tzzs: Int64? //调整总数
}

struct SpFjModal: HandyJSON {
    var fjdz: String?
}

// 任务报告-检查情况
struct SpRwbgjcModal: HandyJSON {
    var id: Int64? //任务项ID
    var rwjlid: Int64? //任务记录ID
    var rwmc: String? //任务项名称
    var rwlxmc: String? //任务类型名称
    var rwzt: String? //任务状态：1 待检查 2 合格 3不合格 4 不涉及
    var sfzg: String?
    var zgzt: String?
    var tjsj: String? //提交时间
    var zgrq: String?
    var fzrmc: String?
    var jcrmc: String?
    var fjsm: String? //附加说明
    var tzsm: String?
    var rwjlMbFjs: [SpFjModal]?
}

// 任务报告-调整情况
struct SpRwbgtzModal: HandyJSON {
    var id: Int64? //任务项ID
    var rwjlid: Int64? //任务记录ID
    var rwmc: String? //任务项名称
    var fjsm: String?
    var fzrmc: String?
    var jcrmc: String?
    var rwjlMbFjs: [SpFjModal]?
    var rwlxdm: String?
    var rwlxmc: String?
    var rwmbid: String?
    var rwzt: String?
    var rwztmc: String?
    var sfzg: String?
    var tjsj: String?
    var tzsm: String?
    var zgjls: [SpRwbgtzZgjlModal]?
    var zgrq: String?
    var zgzt: String?
}

struct SpRwbgtzZgjlModal: HandyJSON {
    var id: String?
    var jcrid: String?
    var jcrmc: String?
    var jcsj: String?
    var rwjlid: String?
    var rwxid: String?
    var rwzt: String?
    var rwztmc: String?
    var tjsj: String?
    var tzsm: String?
    var zgfjs: [SpFjModal]?
    var zgrid: String?
    var zgrmc: String?
    var zgz: String?
}
